package com.linln.modules.order.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.linln.common.vo.PageResult;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.linln.modules.order.repository.OrderMapper;
import com.linln.modules.order.domain.Order;
import com.linln.modules.order.service.OrderService;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author : pengliang
 * @version V1.0
 * @Project: timo
 * @Package com.linln.modules.order.service.impl
 * @Descriptio /**
 * @Project: timo
 * @Package com.linln.modules.order.service.impl
 * @Description: TODO
 * @date Date : 2020年12月25日 16:37
 */

@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {

    @Autowired
    private OrderMapper orderMapper;

    @Override
    //获取积分商城订单
    public Map<String, Object> getIntegralMallOrder(Integer pageNum, Integer limit, Long userId, Integer status) {
//        SqlSessionFactoryBuilder
        Map<String, Object> map = new HashMap<>();
        PageHelper.startPage(pageNum + 1, limit);
        PageInfo<Order> pageInfo = new PageInfo<Order>(orderMapper.selectIntegralMallOrder(userId, status));
        map.put("total", pageInfo.getTotal());
        map.put("data", pageInfo.getList());
        return map;
    }

    //通过id获取订单信息
    @Override
    public Order getIntegralMallOrderById(String orderId) {
        return this.getById(orderId);
    }

    //删除订单
    @Override
    public Order getIntegralMallOrderInfo(String orderId) {
        return orderMapper.selectIntegralMallOrderInfo(orderId);
    }

    //获取订单详情信息
    @Override
    public boolean delOrderById(String orderId) {
        return this.removeById(orderId);
    }

    //获取积分订单记录
    public PageResult<Order> getLayuiIntegralOrder(Integer pageNum, Integer limit,Integer status, String orderNumber) {
        PageHelper.startPage(pageNum, limit);
        PageResult<Order> pageResult = new PageResult<Order>();
        PageInfo<Order> pageInfo = new PageInfo<Order>(orderMapper.selectAllIntegralOrder(status,orderNumber));
        pageResult.setData(pageInfo.getList());
        pageResult.setCount(pageInfo.getTotal());
        return pageResult;
    }
}
